package ysf.com.mediumdifficulty;

/**
 * @author ysf
 * @date 2021/6/14 21:05
 */
public class SixthDemos {

    public static void main(String[] args) {
        String str = "abcdefghijk";
        String converts = converts(str, 3);
        System.out.println(converts);
    }

    public static String converts(String s, int numRows) {
        if (numRows == 1) return s;
        StringBuilder ret = new StringBuilder();
        int n = s.length();
        int cycleLen = 2 * numRows - 2;
        for (int i = 0; i < numRows; i++) {
             for (int j = 0; j + i < n; j += cycleLen) {   //每次加⼀个周期
                char c = s.charAt(j + i);
                ret.append(s.charAt(j + i));
                System.out.print(c+" ");
                if (i != 0 && i != numRows - 1 && j + cycleLen - i < n) {  //除去第 0 ⾏和最 后⼀⾏
                    char cs = s.charAt(j + cycleLen - i);
                    System.out.print(cs+" ");
                    ret.append(s.charAt(j + cycleLen - i));
                }else {
                    System.out.print("  ");
                }
            }
            System.out.println();
        }
        return ret.toString();
    }





}
